<?php
namespace App\Module\Admin\Controller;

use App\Common\Controller\AbstractController;
use App\Module\Admin\Request\Child\CreateRequest;
use App\Module\Admin\Request\Child\UpdateRequest;
use App\Module\Admin\Service\ChildService;
use Hyperf\Di\Annotation\Inject;

class ChildController extends AbstractController{

    /**
     * @Inject()
     * @var ChildService $childService
     */
    private $childService;

    public function search(){
        $cname = $this->request->input("cname");
        $pname = $this->request->input("pname");
        $mobile = $this->request->input("mobile");
        $pagesize = $this->request->input("pagesize");

        return $this->response->json($this->childService->search($cname,$pname,$mobile,$pagesize));
    }

    public function add(CreateRequest $request){
        return $this->response->json($this->childService->create($request));
    }

    public function getById(int $id){
        return $this->response->json($this->childService->getById($id));
    }

    public function edit(UpdateRequest $request,int $id){
        return $this->response->json($this->childService->update($request,$id));
    }

    public function delete(int $id){
        return $this->response->json($this->childService->delete($id));
    }

    //父母列表
    public function parents(int $id){
        return $this->response->json($this->childService->parents($id));
    }

    //解绑父母
    public function unbind(int $cid,int $uid){
        return $this->response->json($this->childService->unbind($cid,$uid));
    }
}